Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11576 - Scrolling message / 11576.cpp
blob9a57e1fe8ad2d7afe418abc41d6a8672e035ce28
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <sstream>
6 #include <fstream>
7 #include <numeric>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 int main(){
28 int casos;
29 cin >> casos;
30 while (casos--){
31 int n, w;
32 cin >> n >> w;
33 int ans = 0;
34 string prev(n, ' ');
35 for (int i=0; i<w; ++i){
36 string s;
37 cin >> s;
38 ans += n;
39 for (int i=0; i<n; ++i){
40 if (s.find(prev.substr(i)) == 0){
41 ans -= n - i;
42 break;
45 prev = s;
47 cout << ans << endl;
49 return 0;